<?php
/**
 * kit configuration data
 *
 * load kit config from wak.ini when built from kit id
 * then get config data with accessor methods
 *
 * This file is part of Webappkit, a packages system for PHP web apps
 * @link http://webappkit.net
 * @package webappkit
 * @author J.Ducastel <nospam0@ducastel.name>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
class WakKitCfg {
    /**
     * @param string $id kit's id
     */
    function WakKitCfg($id) {
        // search for wak.ini
        $path=Webappkit::getPathFromId($id).'/wak.ini';
        if (file_exists($path) and $cfg=parse_ini_file($path,true)) {
            $this->cfg=$cfg;
            $this->is_valid=true;
        }
    }

    /**
     * @return bool
     */
    function isValid() {
        return $this->is_valid;
    }

    /**
     * get kit's version
     * @return string
     */
    function getVersion() {
        return isset($this->cfg['kit']['version'])?
            $this->cfg['kit']['version']:'1.0';
    }

    /**
     * @return string
     */
    function getClass() {
        return isset($this->cfg['kit']['class'])?
            strtolower($this->cfg['kit']['class']):'wakkit';
    }

    /**
     * @return string 5.*|4.3-5.2|4.4+
     */
    function getPhpRange() {
        return isset($this->cfg['kit']['phprange'])?
            strtolower($this->cfg['kit']['phprange']):'*';
    }

    /**
     * @return string
     */
    function getDescription() {
        return isset($this->cfg['kit']['desc'])?
            $this->cfg['kit']['desc']:'';
    }

    /**
     * list dependencies
     * = kits to load and their version
     * @return array(kit_id => version)
     */
    function getDependencies() {
        return (isset($this->cfg['load_kits']) and is_array($this->cfg['load_kits']))?
            $this->cfg['load_kits']:array();
    }

    /**
     * list classes to load
     * @return array(string path)
     */
    public function getFiles() {
        return (isset($this->cfg['load_files']) and is_array($this->cfg['load_files']))?
            $this->cfg['load_files']:array();
    }

    /**
     * list classes and their definition file
     * @return array(class => path)
     */
    function getClasses() {
        return (isset($this->cfg['load_classes']) and is_array($this->cfg['load_classes']))?
            $this->cfg['load_classes']:array();
    }

    /**
     * list subkits to load
     * @return array (name => ?)
     */
    function getSubkits() {
        return (isset($this->cfg['load_subkits']) and is_array($this->cfg['load_subkits']))?
            $this->cfg['load_subkits']:array();
    }

    /**
     * list tools and their class
     * @return array(name => class)
     */
    function getTools() {
        return (isset($this->cfg['tools']) and is_array($this->cfg['tools']))?
            $this->cfg['tools']:array();
    }

    /**
     * @var array kit config as loaded from wak.ini
     */
    var $cfg=array();

    /**
     * @var bool
     */
    var $is_valid;
}